import allure
import pytest
import requests
from selenium import webdriver

@pytest.fixture(scope='function')
def login():
    JSESSIONID='D042FEA5B80D171542182132C87B47A0'

    # 设置URL
    url = 'http://47.113.229.131:9080/jeewms/loginController.do?checkuser'
    # 设置data
    data = {
        'userName':'admin',
        'password':'llg123',
        'randCode':'3677',
        'langCode':'zh-cn'
    }
    # 设置 headers
    headers = {
        'Content-Type': 'application/x-www-form-urlencoded',
        'Cookie': JSESSIONID
    }
    login = requests.post(url=url, headers=headers, data=data)
    yield JSESSIONID
    allure.attach.file(
        r'C:\Users\20176\Desktop\yuekao\case\log.txt',
        name='log.txt',
        attachment_type=allure.attachment_type.TEXT
    )


@pytest.fixture(scope='function')
def driver():
    # 浏览器驱动初始化
    driver = webdriver.Edge()
    # 设置最大窗口
    driver.maximize_window()
    # 等待
    driver.implicitly_wait(10)
    yield driver
    # 关闭浏览器
    driver.close()
    driver.quit()

